package com.example.dts.controller;

import com.example.dts.controller.base.BaseController;
import com.example.dts.controller.base.OR;
import com.example.dts.model.Studio;
import com.example.dts.model.ro.StudioRO;
import com.example.dts.model.vo.StudioVO;
import com.example.dts.service.StudioService;
import io.swagger.annotations.Api;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/studio")
@Api(value = "直播间相关", tags = {"直播间相关"})
public class StudioController extends BaseController {

    @Resource
    private StudioService studioService;

    /**
     * 创建直播间
     * @param studioRO
     * @return
     */
    @PostMapping("/createStudio")
    public ResponseEntity<OR<StudioVO>> createRoom(@RequestBody StudioRO studioRO){
        String userId = currentUser();
        return processData(()-> {
            try {
                return studioService.createStudio(studioRO, userId);
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        },this::processException);
    }

    /**
     * 上传封面
     * @param file
     * @return
     */
    @PostMapping("/uploadImg")
    public ResponseEntity<OR<String>> uploadImg(@RequestParam("cover") MultipartFile file){
        String userId = currentUser();
        return processData(()->studioService.uploadImg(file, userId),this::processException);
    }

    /**
     * 热门直播
     * @return
     */
    @PostMapping("/hotLiveList")
    public ResponseEntity<OR<List<Studio>>> getHotLives(){
        return processData(()->studioService.getHotLives(),this::processException);
    }

}
